<template>
<view>
<view class="container" v-if="orderData">
  <form @submit="submitOrder" report-submit>
    <view v-if="setting.addressType!=2&&orderData.orderType!=17&&orderData.orderType!=7&&orderData.orderType!=20&&orderData.orderType!=19" style="padding-top:20rpx">
      <view class="distribution_mode" v-if="showTopSelect">
        <view class="delivery_door" @tap="selectType" data-type="0" :style="'color:' + (mendianZiti==0?setting.defaultColor:'') + ';background:' + (mendianZiti==0?'':'#eee')">
          <image class="delivery_door_icon" src="https://image1.sansancloud.com/xianhua/2019_1/14/15/49/33_894.jpg"></image>
          <text class="delivery_door_text">配送上门</text>
        </view>
        <view class="ziti_type" @tap="selectType" data-type="1" :style="'color:' + (mendianZiti==1?setting.defaultColor:'') + ';background:' + (mendianZiti==1?'':'#eee')">
          <image class="ziti_type_icon" src="https://image1.sansancloud.com/xianhua/2019_1/14/15/51/38_685.jpg"></image>
          <text class="ziti_type_text">到店服务</text>
        </view>
      </view>
      <view class="addrItems" @tap="showOtherArr" v-if="mendianZiti!=1"> 
        <view class="addrItems_info">
          <image mode="aspectFit" src="https://image1.sansancloud.com/xianhua/2019_12/12/13/49/30_402.jpg?x-oss-process=style/preview_120"></image>
          <block v-if="orderData.addressId == 0">
            <view>
              <text class="addrName">点击添加地址</text>
            </view> 
          </block>
          <block v-else>
            <view class> 
              <text class="addrName">收货人：{{orderData.buyerName}}  </text>
              <text class="font2" style="margin-top:10rpx">联系电话：{{orderData.buyerTelno}}</text>
              <text class="font2">收货地址：{{orderData.buyerProvince}} {{orderData.buyerCity}} {{orderData.buyerArea}} {{orderData.buyerAddress}}</text>
            </view>
          </block>
          
        </view> 
        <image mode="aspectFill" src="https://image1.sansancloud.com/xianhua/2019_12/12/13/50/4_17.jpg?x-oss-process=style/preview_120"></image>
      </view>
      <!-- 自提 -->
      <view class="addrItems" v-else> 
        <view class="addrItems_info">
          <image mode="aspectFit" src="https://image1.sansancloud.com/xianhua/2019_12/12/13/49/30_402.jpg?x-oss-process=style/preview_120"></image>
          <view v-if="belongMendian.name" @click.stop="clickCatch" :data-info="belongMendian"> 
            <text class="addrName">店铺名：{{belongMendian.name}}  </text>
            <text class="font2" style="margin-top:10rpx" v-if="belongMendian.address">门店地址：{{belongMendian.address}}</text>
            <text class="font2" v-else>{{belongMendian.province}}-{{belongMendian.city}}-{{belongMendian.province}}</text>
          </view>
          <view v-else> 
            <text class="addrName">店铺名：{{belongMendian}}  </text>
          </view>
        </view> 
        <view class="selectStore" @click.stop="tolinkUrl" :data-link="'nearby_stores.html?order=' + orderData.orderNo">
          <image class="selectStoreIcon" mode="aspectFill" src="https://image1.sansancloud.com/xianhua/2019_12/12/13/50/4_17.jpg?x-oss-process=style/preview_120"></image>
        </view>
      </view>
      <!-- <view class='buyInfo' wx:if="{{mendianZiti==1&&!sendOptionData&&!showAddressForm}}">
        <text class='name'>提货人信息</text>
        <input class='input_name' name="contactName" bindinput="contactNameInput" value='{{orderData.contactName||""}}' placeholder='请输入提货人'></input>
        <input class='input_telno' name="contactTelno" bindinput="contactTelnoInput" value='{{orderData.contactTelno||""}}' placeholder='请输入提货人手机号'></input>
      </view> -->
    </view>
    <!-- 扫码点餐头部 -->
    <view class="table_info" v-if="orderData.orderType==7">
        <view class="table_info_left">
            <image class="table_info_icon" src="https://image1.sansancloud.com/xianhua/2019_12/16/16/5/47_913.jpg?x-oss-process=style/preview_120"></image>
            <text>桌台 ：{{orderData.tableName}}</text>
        </view>
    </view>
    <!-- 选择服务人员 -->
    <view class="addrItems" style="margin-top:20rpx;border-radius:6rpx;" v-if="setting.selectServantTypeId!=0" @click.stop="tolinkUrl" :data-link="'location_servant_map.html?reqType=order&mendianId=' + belongMendian.id||0 + '&servantTypeId=' + orderData.selectServantTypeId"> 
      <view class="addrItems_info">
        <image mode="aspectFit" src="https://image1.sansancloud.com/xianhua/2019_10/11/14/43/9_878.jpg?x-oss-process=style/preview_120"></image>
        <view v-if="belongServant" @click.stop="clickCatch" :data-info="belongServant"> 
          <text class="addrName">{{properties.alias_yewuyuan||"服务员"}}：{{belongServant.name}}  </text>
          <!-- <text class='font2' style='margin-top:10rpx' wx:if="{{belongServant.address}}">服务类型：{{belongServant.address}}</text> -->
        </view>
        <view v-else> 
          <text class="addrName">请选择{{properties.alias_yewuyuan||"服务员"}}</text>
        </view>
      </view> 
      <view class="selectStore">
        <image class="selectStoreIcon" mode="aspectFill" src="https://image1.sansancloud.com/xianhua/2019_12/12/13/50/4_17.jpg?x-oss-process=style/preview_120"></image>
      </view>   
    </view>
    <!-- 以下是订单部分 -->
    <view class="server_container" v-if="orderData.orderType!=18&&orderData.orderType!=19">
      <view v-if="orderData.orderType!=17&&orderData.orderType!=20">{{orderData.storageName}}</view>
      <!-- <view v-else-if="orderData.orderType==18"></view> -->
      <!-- 表单活动 -->
      <view v-else>{{orderData.belongShopName}}</view>
    </view>
 
    <view class="cartContainer"> 
      <view class="cartShopName">
        <view class="font1">
          <text v-if="orderData.orderType!=17&&orderData.orderType!=20">{{orderData.belongShopName}}</text>
          <text v-else-if="orderData.orderType==17">{{orderData.venuesCells[0].venues.name}}（{{orderData.venuesDate}}）</text>
          <text v-else-if="orderData.orderType==20">{{orderData.course.title}}</text>
          <view class="" v-if="orderData.promotionName">{{orderData.promotionName}}</view> 
          <!-- marginleft -->
        </view>
        <view class="color" :style="'color:' + setting.defaultColor">
            合计:￥ {{orderData.goodsAmount  - orderData.youhuiAmount-orderData.orderJifen.tuijianDikouAmount}}
            <text v-if="orderData.prepayAmount>0">【预付￥{{orderData.prepayAmount}}</text>
            <text v-if="orderData.prepayAmount>0&&!orderData.needJifen">】</text>
            <text v-if="orderData.needJifen>0&&!orderData.prepayAmount">【</text>
            <text v-if="orderData.needJifen>0">+{{orderData.needJifen}}积分】</text>
        </view>
      </view>
      <!-- 产品 -->
      <view class="cartItems" v-if="orderData.orderType!=17&&orderData.orderType!=20" v-for="(orderItem, index) in orderData.orderItems||orderData.venuesCells" :key="index">
        <view class="itemCheckbox">
          <image mode="aspectFill" :src="orderItem.itemIcon + '?x-oss-process=style/preview'"></image>
        </view>
        <view class="item_infomation">
          <view class="item_infomation_name">{{orderItem.itemName}}</view>
          <view class="item_infomation_name_measure" v-if="!!orderItem.measureCartesianId">{{orderItem.measures}}</view>
          <view class="item_infomation_nums"> 
            <text class="flexCenter">x {{orderItem.itemCount}}</text>
          </view>
          <view class="item_infomation_money" :style="'color:' + setting.defaultColor">
             单价:￥<text v-if="orderItem.productItem.promotion&&orderItem.productItem.promotion!=0">{{orderItem.productItem.promotionPrice}}</text>
             <text v-else> {{orderItem.itemPrice}}</text>
             <text class="tagPrice" v-if="orderItem.itemTagPrice>orderItem.itemPrice">/￥{{orderItem.itemTagPrice}}</text>
          </view>
          <view class="salesStrategyList" v-if="orderItem.saleStrategyNo">
            <view class="salesStrategyItem" :style="'border:1rpx solid ' + setting.defaultColor">
              <text :style="'color:' + setting.defaultColor">{{orderItem.saleStrategyName}}</text>
            </view>
          </view>
        </view>
      </view>
      <!-- 场馆 -->
      <view class="venues_cell_list" v-if="orderData.orderType==17">
        <view class="venues_cell_item" :style="'background:' + setting.defaultColor" v-for="(venuesCellItem, index) in orderData.venuesCells[0].cells" :key="index">
           <text class="venues_cell_item_time">{{venuesCellItem.startTimeStr}}-{{venuesCellItem.endTimeStr}}</text>
           <text class="venues_cell_item_price">￥{{venuesCellItem.cellPrice}}</text>
           <text class="circular"></text>
        </view>
      </view>
      <!-- 课程 -->
      <view class="course_list" v-if="orderData.orderType==20">
        <!-- <view class="venues_cell_item" :style="'background:' + setting.defaultColor" v-for="(venuesCellItem, index) in orderData.venuesCells[0].cells" :key="index">
           <text class="venues_cell_item_time">{{venuesCellItem.startTimeStr}}-{{venuesCellItem.endTimeStr}}</text>
           <text class="venues_cell_item_price">￥{{venuesCellItem.cellPrice}}</text>
           <text class="circular"></text>
        </view> -->
        <view class="course_item" :data-url="'course_detail.html?instanceId='+orderData.courseInstance.id" @tap="tolinkUrl">
            <view class="course_item_left">
                <image :src="orderData.courseInstance.banner" class="course_item_banner" mode="aspectFit"></image>
                <text class="course_item_tag" v-if="orderData.courseInstance.chapterSectionType==1">专栏</text>
                <text class="course_item_tag" v-else-if="orderData.courseInstance.chapterSectionType==2">系列课</text>
                <text class="course_item_tag" v-else>课程</text>
            </view>
            <view class="course_item_right">
                <text class="course_item_name">{{orderData.courseInstance.courseTitle}}</text>
                <text class="course_item_describe">{{orderData.courseInstance.description}}</text>
                <scroll-view class='tags_content' scroll-x v-if="orderData.courseInstance.tags">
                  <text class='tags_item' v-for='(tagItem,tagIndex) in orderData.courseInstance.tagArray' :key='tagIndex'>{{tagItem}}</text>
                </scroll-view>
                <view class="course_item_right_bottom">
                    <text class="course_item_num" v-if="orderData.courseInstance.sectionCount&&orderData.courseInstance.sectionCount>1">课时 {{orderData.courseInstance.sectionCount}}</text>
                    <text class="course_item_price_type" v-if="orderData.courseInstance.coursePrice<=0">免费</text>
                    <text class="course_item_price_type" v-else>￥{{orderData.courseInstance.coursePrice}}</text>
                </view>
            </view>
        </view>
      </view>
      <!-- 表单活动 -->
      <block v-if="orderData.orderType==18&&orderData.formCommit&&orderData.formCommit.attendMeasureListObj">
          <view class="cartItems" v-for="(attendMeasureItem, index) in orderData.formCommit.attendMeasureListObj" :key="index">
            <view class="itemCheckbox">
                
              <!-- <image mode='aspectFill' src='{{orderData.formCommit.commitRoleObjectIcon}}?x-oss-process=style/preview'></image> -->
            </view>
            <view class="item_infomation" style="height:110rpx;">
              <view class="item_infomation_name">{{attendMeasureItem.attendMeasureName}}</view>
              <!-- <view class='item_infomation_name_measure' wx:if='{{!!attendMeasureItem.measureCartesianId}}'>{{attendMeasureItem.measures}}</view> -->
              <view class="item_infomation_nums" style="top:50rpx"> 
                <text class="flexCenter">x {{attendMeasureItem.buyCount}}</text>
              </view>
              <view class="item_infomation_money" :style="'color:' + setting.defaultColor">
                单价:￥<text>{{attendMeasureItem.attendPrice}}</text>
                <!-- <text class='tagPrice' wx:if='{{orderItem.itemTagPrice>orderItem.itemPrice}}'>/￥{{orderItem.itemTagPrice}}</text> -->
              </view>
            </view>
          </view>
      </block>
      <view class="butn_container" v-if="orderData.orderType!=18&&orderData.orderType!=19">
          <text>运费（{{orderData.yunfeiAmountTip}}）</text>
          <text>￥{{orderData.yunfeiAmount}}</text>
      </view>
      <!-- <view class="butn_container" v-if="tableID&&tableID!=''">
          <text>桌号</text>
          <text>{{tableID}}</text>
      </view> -->
      <!-- 优惠券 -->
      <view class="butn_container" v-if="coupon2.length != 1">
          <view class="youhuiquan">
            <text>优惠券:</text>
            <picker @change="bindPickerChange" id="test111" mode="selector" :value="index" :range="coupon2">
              <block v-if="coupon2.length == 1">
                <view>没有优惠券</view>
              </block> 
              <block v-else>
                <view>{{coupon2[index]}}</view>
              </block> 
            </picker>
            
          </view>
          <text>-￥{{orderData.youhuiAmount}}</text>
      </view>

    <!-- 积分抵扣 -->
      <block v-if="orderData.orderJifen.userJifen&&orderData.orderJifen.tuijianDikou && orderData.orderJifen.tuijianDikou != 0">
        <checkbox-group @change="jifenChange">
          <label class="jifenContainer">
            <view>
              <checkbox :color="setting.defaultColor" :checked="jifenState" :value="orderData.orderJifen.tuijianDikou"></checkbox>
              <text>使用{{orderData.orderJifen.tuijianDikou}}积分</text>
            </view>
            <view :style="'color:' + setting.defaultColor">抵扣￥{{orderData.orderJifen.tuijianDikouAmount}}</view>
          </label>
        </checkbox-group>
      </block>
      <!-- 留言 -->
      <!-- <view class='butn_container2'>
        <text>留言</text>
        <input placeholder='给卖家留言' maxlength='200' value='{{orderData.buyerScript}}' bindinput='getBuyerScript'></input>
      </view> -->
    </view>
<!-- 表单地址 -->
    <form-detail-component id="orderForm" :receiveData="sendOptionData" showTitle="false" showBtn="false" :userAddressCustomFormCommitId="userAddressCustomFormCommitId" v-if="sendOptionData&&showAddressForm" showSubmitPopup="false" @sendDataFun="getDataFun"></form-detail-component>
    <!-- 支付方式 -->
    <block v-if="orderData.orderType!=7">
        <view class="payName">支付方式</view>
        <radio-group class="radioGroup" @change="payWayChange">
          <label :class="(checkedRadio == 0?'payChecked':'payWay')" data-index="0" @tap="radioChance" v-if="setting.zfWxzfEnable && setting.zfWxzfOn"><!--  -->
            <radio hidden="true" :color="setting.defaultColor" :checked="checkedRadio == 0" value="3"></radio>
            <text>微信支付</text>
          </label>
          <label :class="(checkedRadio == 1?'payChecked':'payWay')" data-index="1" @tap="radioChance" v-if="setting.zfYezfEnable && setting.zfYezfOn"><!--  -->
            <radio hidden="true" :color="setting.defaultColor" :checked="checkedRadio == 1" value="2"></radio>
            <text>{{properties.alias_yue||'余额'}}支付</text>
          </label>
          <label :class="(checkedRadio == 2?'payChecked':'payWay')" data-index="2" @tap="radioChance" v-if="setting.zfOfflineEnable && setting.zfOfflineOn"><!--  -->
            <radio hidden="true" :color="setting.defaultColor" :checked="checkedRadio == 2" value="5"></radio>
            <text>线下支付</text>
          </label>
          <label :class="(checkedRadio == 3?'payChecked':'payWay')" data-index="3" @tap="radioChance" v-if="setting.zfHdfkEnable && setting.zfHdfkOn"><!--  -->
            <radio hidden="true" :color="setting.defaultColor" :checked="checkedRadio == 3" value="0"></radio>
            <text>货到付款</text>
          </label>
        </radio-group>
    </block>
    <block v-if="checkedRadio == 2">
        <view class='imgType common'>
          <view class='imgName'>
            <text>支付凭证</text>
          </view>
          <view class='upload'>
            <view class='uploadedImg' v-if="orderMessage.offPayedImage.length!=0">
              <view class='removeImgIcon' @tap='removeFile'><text>x</text></view>
              <image :data-imageUrl='orderMessage.offPayedImage' :data-link='orderMessage.offPayedImage' @longpress='saveImageToLocal' @tap='toImgUrl' class='uploadedImgUrl' :src="orderMessage.offPayedImage" mode='aspectFill'></image>
            </view>
            <view class='uploadImg' @tap='addCommitImage'>
              <image class='uploadImgIcon' src='https://image1.sansancloud.com/jianzhan/2018_10/22/18/4/3_874.jpg?x-oss-process=style/preview_120'></image>
              <text style='font-size:24rpx;color:#555;margin-top:10rpx'>添加图片</text>
            </view>
          </view>
        </view>
        <!-- 多行文本 -->
        <view class='inputString common' style='align-items:flex-start;padding:10px;flex-direction:column;'>
          <view class='inputName'>
            <text>支付备注</text>
          </view>
          <textarea  maxlength="-1" auto-height="" @input="offPayedRemarkFun"  data-name="offPayedRemark" placeholder='请输入线下支付备注' :value='orderMessage.offPayedRemark' name="offPayedRemark"/>
        </view>
    </block>
    <block v-if="coupon2.length <= 1&&!gotCouponListId">
      <button class="fottButn" formType="submit" :style="'background:' + setting.defaultColor">提交订单</button>
    </block>
    <block v-else-if="gotCouponListId||sureUseCouponState">
      <button class="fottButn" formType="submit" :style="'background:' + setting.defaultColor">提交订单</button>
    </block>
    <block v-else>
      <picker class="fottButn" id="test112" data-type="submit" :style="'background:' + setting.defaultColor" @change="bindPickerChange" mode="selector" :value="index" :range="coupon2" @cancel="bindPickercancel">
        <view>提交订单</view>
      </picker>
    </block>
    <view class="agreement" v-if="isAgreement">
      <icon v-if="!agreementState" @tap="changeAgreement" data-type="1" type="circle" size="34rpx"></icon> 
      <icon v-else @tap="changeAgreement" data-type="0" type="success" size="34rpx"></icon>
      <text class="agreementName" @click.stop="tolinkUrl" data-link="custom_page_order_agreement.html">《订单协议》</text>
      <text class="agreementTip">提交订单表示您同意协议内容</text>
    </view>
</form>
</view>
<view class="height"></view>


<view v-if="showArr" class="zhezhao" @tap="closeShowArr"></view>
<view v-if="showArr" class="OtherArrContainer">
  <view class="addnewarr" @tap="toaddress_newFun" :style="'color:' + setting.defaultColor">新增地址</view>
  <view class="addnewarr" @tap="wx_toaddress_newFun" :style="'color:' + setting.defaultColor" v-if="setting.addressType==0">微信添加</view>
  <view class="addrItems2" v-for="(addr, index) in addrArr" :key="index">
    <view class="addrItems2_left" :data-chooseId="addr.id" @tap="chooseNewAddr">
      <image mode="aspectFit" src="https://image1.sansancloud.com/xianhua/2019_12/12/13/49/30_402.jpg?x-oss-process=style/preview_120"></image>
      <view class="addrItems2_left_text">
        <text>{{addr.contactName}} {{addr.telNo}}</text>
        <text class="font2">{{addr.province}} {{addr.city}} {{addr.area}} {{addr.address}}</text>
      </view>        
    </view>
    <view class="address_modify_in_time" @tap="addressModifyInTime" :data-id="addr.id">
        <image mode="aspectFit" src="https://image1.sansancloud.com/aikucun/2018_03/21/16/00/16_502.jpg"></image>
    </view>
  </view>
</view>
</view>
</template>

<script>

export default {
  data() {
    return {
      orderData: null,
      selectServant:null,
      selectStore: null,
      reqStore: false,
      reqServant: false,
      // showSelectCoupon:false,
      sureUseCouponState: false,
      reqAddress: false,
      showTopSelect: false,
      showAddressForm: false,
      orderNo: '',
      checkedRadio: 0,
      agreementState: true,
      isAgreement: false,
      jifenState: true,
      //优惠券 
      getEditOrderDetailData: null,
      coupon: [],
      coupon2: [],
      index: 0,
      //
      gotCouponListId: 0,
      mendianZiti: -1,
      couponMoney: 0,
      sendOptionData: null,
      userAddressCustomFormCommitId: '',
      belongServant: null,
      setting: null,
      loginUser: null,
      //otherArr
      showArr: false,
      addrArr: null,
      hasAddnewAddr: false,
      //will sent
      orderMessage: {
        platformNo: '',
        gotCouponListId: '',
        userId: '',
        orderNo: '',
        payType: '3',
        buyerScript: '',
        addressId: '',
        jifenDikou: '0',
        buyerBestTime: '',
        changeOrderMendianId: 0,
        contactName: "",
        contactTelno: "",
        offPayedImage:[],
        offPayedRemark:'',
      },
      // 地址从微信上调取需要的参数
      needParam: {
        contactName: '',
        telno: '',
        province: '',
        city: '',
        district: '',
        detail: '',
        //详细地址
        longitude: '',
        latitude: '',
        defaultAddress: 0
      },
      showSelectCoupon: false,
      belongMendian: "",
      allowMendianZiti: "",
      tableID: "",
      properties: ""
    };
  },

  props: {},
  onLoad: function (option) {
    var that = this;
    console.log("========app.setting======", getApp().globalData.setting,getApp().globalData.loginUser, getApp().globalData.properties);
    console.log("========option======", option);
    // if((getApp().globalData.loginUser&&(!getApp().globalData.loginUser.platformUser.belongMendian||getApp().globalData.loginUser.platformUser.belongMendian==0))||getApp().globalData.setting.platformSetting.forceSelectMendian==1){
    //     let url='nearby_stores.html?order=orderNo';
    //     that.tolinkUrl(url);
    // }
    try {
      var tableID = wx.getStorageSync('tableID');

      if (tableID && tableID != "") {
        that.setData({
          tableID: tableID
        });
      }
    } catch (e) {}

    console.log("=========tableID===========", tableID);
    that.setData({
      setting: getApp().globalData.setting.platformSetting,
      loginUser: getApp().globalData.loginUser,
      properties: getApp().globalData.properties
    });
    console.log("==================option===================", option.orderNo);
    let orderData = option.orderNo; //  获取订单号

    if (!!orderData && orderData != "") {
      that.orderNo = orderData;
      // that.setData({
      //   orderData: orderData
      // });
      that.getEditOrderDetail();
      that.getParac();
      console.log("===================", that.orderData);
    }
  },
  onShow: function () {
    let that = this;
    
    // #ifdef MP
    that.getUserLocation();
    
    // #endif
    // #ifdef H5||APP-PLUS
    that.gainUserLocation()
    // #endif
    if (!!that.orderNo) {
      //this.getEditOrderDetail()
      that.getAddr();
    }

    if (that.hasAddnewAddr) {
      that.showOtherArr(); // this.getAddr()
    }

    let addrEditParam = getApp().globalData.addrEditParam;

    if (addrEditParam && this.hasEditAddr) {
      console.log(addrEditParam);
      that.changOutAddr(addrEditParam);
    }
    if (that.reqStore) {
      //选择门店
      console.log("从附近店铺页面返回");
      var pages = getCurrentPages();
      var currPage = pages[pages.length - 1]; //当前页面

      console.log(currPage); //就可以看到data里mydata的值了

      if (currPage.data.selectStore) {
        console.log("选择门店了", currPage.data.selectStore);
        that.setData({
          belongMendian: currPage.data.selectStore
        });
        that.orderMessage.changeOrderMendianId = currPage.data.selectStore.id;
      } else {
        console.log("没选择门店");
      }
    }
    if (that.reqServant) {
      //选择服务员
      console.log("从服务人员列表页面返回");
      var pages = getCurrentPages();
      var currPage = pages[pages.length - 1]; //当前页面

      console.log("从服务人员列表页面返回",currPage.data.selectServant);
      if (currPage.data.selectServant) {
        console.log("选择服务员了", currPage.data.selectServant);
        that.setData({
          belongServant: currPage.data.selectServant
        });
        that.orderMessage.servantId = currPage.data.selectServant.id;
      } else {
        console.log("没选择服务员");
      }
    }

    if (that.reqAddress) {
      //选择地址
      console.log("从添加地址页面返回");
      var pages = getCurrentPages();
      var currPage = pages[pages.length - 1]; //当前页面

      console.log(currPage); //就可以看到data里mydata的值了

      if (currPage.data.selectAddress) {
        console.log("保存好了地址", currPage.data.selectAddress);
        let selectAddr = currPage.data.selectAddress;
        that.changeAddressData(selectAddr.id);
        let newData = that.orderData;
        newData.buyerName = selectAddr.contactName;
        newData.buyerTelno = selectAddr.telNo;
        newData.buyerProvince = selectAddr.province;
        newData.buyerCity = selectAddr.city;
        newData.buyerArea = selectAddr.area;
        newData.buyerAddress = selectAddr.address;
        newData.addressId = selectAddr.id;
        that.orderMessage.addressId = selectAddr.id;
        that.setData({
          orderData: newData
        });
      } else {
        console.log("取消保存地址");
      }
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},
  methods: {
    // 判断是否有协议页面；
    getParac: function () {
      var that = this;
      var customIndex = getApp().globalData.AddClientUrl("/custom_page_order_agreement.html", {}, 'get', '1'); //拿custom_page

      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("====== res.data=========", res.data);

          if (!res.data.errcode || res.data.errcode == '0') {
            wx.hideLoading();
            that.setData({
              isAgreement: true
            });
          } else {
            console.log('加载失败');
            that.setData({
              isAgreement: false
            });
          }
        },
        fail: function (res) {
          console.log('------------2222222-----------', res);
          that.setData({
            isAgreement: false
          });
          wx.hideLoading();
        }
      });
    },

    changeAgreement(e) {
      let that = this;
      console.log('checkbox发生change事件，携带value值为：', e);
      let type = e.target.dataset.type;

      if (type == 1) {
        that.setData({
          agreementState: true
        });
      } else {
        that.setData({
          agreementState: false
        });
      }
    },

    radioChance: function (e) {
      var index = e.currentTarget.dataset.index;
      this.setData({
        checkedRadio: index
      });
    },

    /* 积分抵扣 */
    jifenChange: function (e) {
      let that = this;
      console.log("==e==", e);
      let jifen = e.detail.value[0];
      console.log("==jifen==", jifen);

      if (jifen) {
        that.jifenState = true;
        that.orderMessage.jifenDikou = jifen;
      } else {
        that.jifenState = false;
        that.orderMessage.jifenDikou = 0;
      }

      console.log("that.orderMessage", that.orderMessage);
    },

    /* 获取地址列表 */
    showOtherArr: function () {
      var customIndex = getApp().globalData.AddClientUrl("/get_login_user_address_list.html");
      var that = this; // wx.showLoading({
      //   title: 'loading'
      // })

      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("获取地址列表", res);
          wx.hideLoading();
          that.setData({
            addrArr: res.data.result,
            showArr: true
          });
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    toaddress_newFun: function () {
      this.setData({
        hasAddnewAddr: true
      });
      wx.navigateTo({
        url: '/pages/add_address/index'
      });
    },
    wx_toaddress_newFun: function () {
      let that = this;
      wx.chooseAddress({
        success: function (res) {
          console.log(res.userName); //收货人姓名

          console.log(res.postalCode); //邮编

          console.log(res.provinceName); // 省

          console.log(res.cityName); //  市

          console.log(res.countyName); //区

          console.log(res.detailInfo); // 详细地址

          console.log(res.telNumber); //手机号

          that.needParam.contactName = res.userName; //名字

          that.needParam.province = res.provinceName; //省

          that.needParam.city = res.cityName; //市

          that.needParam.district = res.countyName; //

          that.needParam.telno = res.telNumber; //手机号

          that.needParam.detail = res.detailInfo;
          that.needParam.defaultAddress = "1"; //默认

          console.log("参数" + JSON.stringify(that.needParam));
          let customIndex = getApp().globalData.AddClientUrl("/add_address.html", that.needParam, 'post');
          wx.request({
            url: customIndex.url,
            data: customIndex.params,
            header: getApp().globalData.headerPost,
            method: 'POST',
            success: function (res) {
              console.log(res);
              wx.hideLoading();
              getApp().globalData.addrEditParam = that.needParam; // 添加成功后重新刷新列表

              that.showOtherArr();
            },
            fail: function (res) {
              wx.hideLoading();
              getApp().globalData.loadFail();
            }
          });
        }
      });
    },
    chooseNewAddr: function (e) {
      getApp().globalData.showToastLoading('loading', true);
      let that = this; //console.log(e.currentTarget.dataset.chooseid)

      var addrArr = this.addrArr;
      console.log(addrArr);
      var addressId = e.currentTarget.dataset.chooseid;
      console.log("addressId" + addressId);
      that.changeAddressData(addressId);
      var selectAddr = null;

      for (let i = 0; i < addrArr.length; i++) {
        if (addressId == addrArr[i].id) {
          selectAddr = addrArr[i];
        }
      }

      console.log(selectAddr);
      let newData = this.orderData;
      newData.buyerName = selectAddr.contactName;
      newData.buyerTelno = selectAddr.telNo;
      newData.buyerProvince = selectAddr.province;
      newData.buyerCity = selectAddr.city;
      newData.buyerArea = selectAddr.area;
      newData.buyerAddress = selectAddr.address; // this.data.orderData.buyerName = selectAddr.contactName

      newData.addressId = addressId;
      this.orderMessage.addressId = addressId;
      this.setData({
        orderData: newData,
        showArr: false
      });
      wx.hideLoading();
    },
    changeAddressData: function (addressId) {
      let that = this;
      let params = {
        addressId: addressId,
        orderNo: that.orderData.orderNo
      };
      var customIndex = getApp().globalData.AddClientUrl("/change_order_address.html", params, 'post');
      getApp().globalData.showToastLoading('loading', true); //拿custom_page 

      wx.request({
        url: customIndex.url,
        header: getApp().globalData.headerPost,
        data: customIndex.params,
        method: 'POST',
        success: function (res) {
          console.log('-------地址---------');
          console.log(res.data);

          if (res.data.errcode == '-1') {
            console.log('0');
          } else {
            console.log('1');
            that.getEditOrderDetail();
          }

          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    closeShowArr: function () {
      this.setData({
        showArr: false,
        showSelectCoupon: false
      });
    },

    /* 支付方式 */
    payWayChange: function (e) {
      console.log(e.detail.value);
      this.orderMessage.payType = e.detail.value;
    },
    getBuyerScript: function (e) {
      this.orderMessage.buyerScript = e.detail.value;
    },
    //优惠券
    bindPickercancel: function (e) {
      let that = this;
      console.log("取消按钮", e);
      that.orderMessage.gotCouponListId = 0;
      that.setData({
        index: 0,
        couponMoney: 0,
        gotCouponListId: 0,
        couponMoney: 0,
        sureUseCouponState: true
      });
    },
    bindPickerChange: function (e) {
      console.log("bindPickerChange确定选择", e);
      let that = this;
      let index = e.detail.value;
      let typeState = e.currentTarget.dataset.type;
      that.setData({
        sureUseCouponState: true
      });
      let coupon = that.coupon;

      if (index == 0) {
        that.orderMessage.gotCouponListId = 0;
        that.setData({
          index: index,
          couponMoney: 0,
          gotCouponListId: 0
        });
        that.getEditOrderDetail();
      } else {
        let gotCouponListId = coupon[index].id;
        console.log(gotCouponListId);
        that.orderMessage.gotCouponListId = gotCouponListId;
        that.setData({
          index: index,
          gotCouponListId: gotCouponListId,
          couponMoney: coupon[index].coupon.youhuiAmount
        });
        console.log("===gotCouponListId===", gotCouponListId);
        that.getEditOrderDetail();
      }

      if (typeState && typeState == 'submit') {// that.submitOrder()
      }
    },
    // 这里需要修改
    getavailableCouponsArr: function () {
      var arr = ['no'];
      var arr2 = ['不选择优惠券'];
      var data = this;

      if (data && data.getEditOrderDetailData.availableCoupons) {
        let couponList = this.getEditOrderDetailData.availableCoupons;

        for (let i = 0; i < couponList.length; i++) {
          arr.push(couponList[i]);
          let couponName = '';

          if (couponList[i].coupon.orderAmount != 0) {
            couponName = "满" + couponList[i].coupon.orderAmount + "元减" + couponList[i].couponYouhuiAmount;
            arr2.push(couponName);
          } else {
            couponName = couponList[i].couponYouhuiAmount + '元优惠券';
            arr2.push(couponName);
          }
        }
      }

      this.setData({
        coupon: arr,
        coupon2: arr2
      });
      console.log('----------1----------');
      console.log(arr);
      console.log('----------2----------');
      console.log(arr2);
    },
    getEditOrderDetail: function () {
      var that = this;
      var getParams = {};
      console.log("==setting==", that.setting);
      getParams.orderNo = that.orderNo;
      getParams.gotCouponListId = that.orderMessage.gotCouponListId;
      getParams.mendianZiti = that.mendianZiti;
      var customIndex = getApp().globalData.AddClientUrl("/get_edit_order_detail.html", getParams);
      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log("=====orde detail=======", res);
          let data = res.data;
          if(data.errcode==-1){
            wx.showToast({
              title: data.errMsg,
              image: '/wxcomponents/images/icons/tip.png',
              duration: 2000
            });
            setTimeout(function(){
                wx.navigateBack({})
            },1800)
          }
          if(data.orderType==20&&data.courseInstance&&data.courseInstance.tags){
              let tagArray = data.courseInstance.tags.slice(1, -1).split("][")
              data.courseInstance.tagArray = tagArray;
          }
          if(data.orderType==7){
              that.$set(that.orderMessage,'payType',0)
          }
          if (data.userAddressCustomFormId && data.userAddressCustomFormId > 0) {
            that.setData({
              showAddressForm: true,
              sendOptionData: {
                customFormId: data.userAddressCustomFormId || 0
              }
            });
          } else {
            that.setData({
              sendOptionData: null
            });
          }

          if (data.userAddressCustomFormCommitId) {
            that.setData({
              userAddressCustomFormCommitId: data.userAddressCustomFormCommitId
            });
          }

          if (data.formCommit && data.formCommit.attendMeasureList) {
            data.formCommit.attendMeasureListObj = JSON.parse(data.formCommit.attendMeasureList);
          }

          that.setData({
            getEditOrderDetailData: data,
            orderData: data
          });

          if (data.belongMendian) {
            that.setData({
              belongMendian: data.belongMendian
            });
            that.orderMessage.changeOrderMendianId = data.belongMendian.id;
          }

          if (data.assignServant) {
            that.setData({
              belongServant: data.assignServant
            });
            that.orderMessage.servantId = data.assignServant.id;
          } // 获取门店自提


          let allowMendianZiti = data.allowMendianZiti;
          let showTopSelect = false;
          console.log(allowMendianZiti);
          that.setData({
            allowMendianZiti: allowMendianZiti,
            mendianZiti: data.mendianZiti
          });

          if (allowMendianZiti != 0) {
            showTopSelect = true;
          } else {
            showTopSelect = false;
          }

          that.setData({
            showTopSelect: showTopSelect
          });
          console.log("=====mendianZiti======", that.mendianZiti);
          that.getavailableCouponsArr();
          that.loadMessage();
          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },

    /* 确认订单 */
    submitOrder: function (e) {
      console.log('====formId====', e);
      var that = this;
      that.setData({
        reqAddress: false
      });
      let miniNotifyFormId = that.orderMessage.miniNotifyFormId ? that.orderMessage.miniNotifyFormId : e.detail.formId || '';
      that.orderMessage.miniNotifyFormId = miniNotifyFormId;
      let addressType = that.setting.addressType;
      console.log("=====addressType=====", addressType);
      console.log(that.orderMessage); // 不允许自提的时候没写地址

      if (!that.orderMessage.addressId && that.allowMendianZiti == "0" && addressType != 2 && that.orderData.orderType != 17&& that.orderData.orderType != 7&&that.orderData.orderType!=20) {
        wx.showModal({
          title: '提示',
          content: '请添加收货地址',
          success: function (res) {
            if (res.confirm) {
              that.setData({
                reqAddress: true
              });
              wx.navigateTo({
                url: '/pages/add_address/index?type="order"'
              });
            } else if (res.cancel) {
              that.setData({
                reqAddress: false
              });
            }
          }
        });
      } else {
        // 如果允许自提但没打勾
        if (that.allowMendianZiti != "0" && that.mendianZiti == "0" && !that.orderMessage.addressId && addressType != 2 && that.orderData.orderType != 17&& that.orderData.orderType != 7) {
          wx.showModal({
            title: '提示',
            content: '请添加收货地址',
            success: function (res) {
              if (res.confirm) {
                that.setData({
                  reqAddress: true
                });
                wx.navigateTo({
                  url: '/pages/add_address/index?type="order"'
                });
              } else if (res.cancel) {
                that.setData({
                  reqAddress: false
                });
              }
            }
          });
        } else {
          // 如果是订餐的话携带桌子ID
          // 查找缓存
          console.log("22222222222222");
          let tableId=''
          if(that.orderData.tableId){
              tableId = that.orderData.tableId;
          }
          try {
            let tableIdTwo = wx.getStorageSync('tableID');
            if (tableIdTwo&&tableIdTwo==tableId) {
              tableId = tableIdTwo;
            }
          } catch (e) {} 
          if(tableId){
            that.orderMessage.tableId =tableId
          }
          // 判断是否自提
          console.log("======mendianZiti=========", that.mendianZiti);
          that.orderMessage.mendianZiti = that.mendianZiti; // that.data.mendianZiti == 1 && (!that.orderMessage.contactName || !that.orderMessage.contactTelno) && that.data.setting.addressType != 2 && that.data.orderData.orderType != 17
          // if (that.data.mendianZiti == 1 && (!that.orderMessage.contactName || !that.orderMessage.contactTelno) && that.data.setting.addressType != 2&& !that.data.showAddressForm && that.data.orderData.orderType != 17){
          //   wx.showModal({
          //     title: '提示',
          //     content: '请完善提货人信息！',
          //     success: function (res) {
          //       if (res.confirm) {
          //       } else if (res.cancel) {
          //       }
          //     }
          //   })
          //   return;
          // }

          if (that.isAgreement) {
            if (!that.agreementState) {
              wx.showModal({
                title: '提示',
                content: '请您勾选《订单协议》同意协议内容！',
                success: function (res) {
                  if (res.confirm) {
                    that.setData({
                      agreementState: true
                    });
                  } else if (res.cancel) {}
                }
              });
              return;
            }
          } // 判断是否选择了服务员


          if (that.setting.selectServantTypeId != 0) {
            if (!that.orderMessage.servantId) {
              // wx.showModal({
              //   title: '提示',
              //   content: '请您选择' + (that.data.properties.alias_yewuyuan || "服务员") + '！',
              //   success: function (res) {
              //     if (res.confirm) {
              //       that.setData({ agreementState: true })
              //     } else if (res.cancel) {
              //     }
              //   }
              // })
              let url = 'location_servant_map.html?reqType=order&mendianId=' + that.belongMendian.id || 0 + '&servantTypeId=' + that.orderData.selectServantTypeId;
              that.tolinkUrl(url);
              return;
            }
          } //判断地址类型


          if (that.setting.addressType == 2 || that.orderData.orderType == 17|| that.orderData.orderType == 7||that.orderData.orderType==20) {
            that.orderMessage.addressId = 0;
          } // 判断下单时是否选择了优惠券
          // if (that.data.coupon2.length > 1 && !that.orderMessage.gotCouponListId && !that.data.sureUseCouponState) {
          //   that.setData({ showSelectCoupon: true })
          //   return
          // }


          console.log("=========参数orderMessage===========", that.orderMessage, that.sendOptionData);

          if (!that.sendOptionData) {
            console.log("=====没有表单=====");
            that.toSubmitOrder(that.orderMessage);
          } else {
            console.log("=====有表单=====");
            that.selectComponent("#orderForm").formSubmit();
          }
        }
      }
    },
    getDataFun: function (e) {
      let that = this;
      console.log("===getDataFun===", e);
      that.orderMessage.userAddressCustomFormCommitId = e.detail.formId;
      that.toSubmitOrder(that.orderMessage);
    },
    // continueSubmitOrder:function(e){
    //   let that=this;
    //   console.log("===continueSubmitOrder===",e)
    //   let state=e.currentTarget.dataset.state
    //   if (state=='no'){
    //     that.orderMessage.gotCouponListId = 0
    //   }
    //   that.setData({ sureUseCouponState:true })
    //   that.submitOrder()
    // },
    toSubmitOrder: function (data) {
      var customIndex = getApp().globalData.AddClientUrl("/submit_order.html", data, 'post'); // wx.showLoading({
      //   title: 'loading',
      //   mask: true
      // })

      getApp().globalData.showToastLoading('loading', true);
      wx.request({
        url: customIndex.url,
        data: customIndex.params,
        header: getApp().globalData.headerPost,
        method: 'POST',
        success: function (res) {
          console.log('--------确认订单------- ');
          console.log(res);
          console.log(res.data);

          if (res.data.errcode == '10001') {
            getApp().globalData.loadLogin();
          } else if (res.data.errcode == '-1') {
            wx.hideLoading();
            wx.showModal({
              title: '警告',
              content: res.data.errMsg,
              success: function (res) {
                if (res.confirm) {} else if (res.cancel) {}
              }
            });
            return;
          } else {
            getApp().globalData.payItem = res.data;
            /* 全局传过去吧... */

            wx.hideLoading();
            wx.redirectTo({
              url: '/pages/submit_order_result/index'
            });
          }
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    //增加 购买过程中——及时收获地址——可编辑的状态
    addressModifyInTime: function (e) {
      var addrId = e.currentTarget.dataset.id;

      for (let i = 0; i < this.addrArr.length; i++) {
        if (addrId == this.addrArr[i].id) {
          getApp().globalData.EditAddr = this.addrArr[i];
        }
      }

      this.hasEditAddr = true;
      wx.navigateTo({
        url: '../add_address/index?addrId=' + addrId
      });
    },
    getAddr: function () {
      if (!getApp().globalData.checkIfLogin()) {
        return;
      }

      var customIndex = getApp().globalData.AddClientUrl("/get_login_user_address_list.html");
      var that = this;
      getApp().globalData.showToastLoading('loading', true); //拿custom_page 

      wx.request({
        url: customIndex.url,
        header: getApp().globalData.header,
        success: function (res) {
          console.log('-------地址---------');
          console.log(res.data);

          if (res.data.result.errcode == '-1') {
            console.log('err');
            getApp().globalData.echoErr(res.data.result.errMsg);
          } else {
            that.setData({
              addrArr: res.data.result
            });
          }

          wx.hideLoading();
        },
        fail: function (res) {
          wx.hideLoading();
          getApp().globalData.loadFail();
        }
      });
    },
    // 添加一个地址到
    subMitArrFrom: function (e) {
      console.log(this.needParam);
      var that = this;
      /* 判断地址是否有空的 */

      let pass = this.dellAddrSpace(this.needParam);

      if (pass == '0') {
        /* 判断是编辑还是新增 */
        var customIndex = null;

        if (!this.ifEid) {
          customIndex = getApp().globalData.AddClientUrl("/add_address.html", that.needParam, 'post');
        } else {
          customIndex = getApp().globalData.AddClientUrl("/edit_address.html", that.needParam, 'post');
        } // wx.showLoading({
        //   title: 'loading',
        //   mask: true
        // })


        getApp().globalData.showToastLoading('loading', true);
        wx.request({
          url: customIndex.url,
          data: customIndex.params,
          header: getApp().globalData.headerPost,
          method: 'POST',
          success: function (res) {
            console.log(res);
            wx.hideLoading();
            getApp().globalData.addrEditParam = that.needParam;
            wx.navigateBack();
          },
          fail: function (res) {
            wx.hideLoading();
            getApp().globalData.loadFail();
          }
        });
      } else {
        wx.showToast({
          title: pass,
          image: '/wxcomponents/images/icons/tip.png',
          duration: 2000
        });
      }
    },
    clickCatch: function (e) {
      console.log(e.currentTarget.dataset.info);
      var info = e.currentTarget.dataset.info;
      console.log(info);
      let latitude = info.latitude;
      let longitude = info.longitude;
      let name = info.name;
      let address = info.address; // 判断金纬度是否为空

      if (latitude == "" || longitude == "") {
        console.log("判断金纬度是否为空");
        wx.showModal({
          title: '提示',
          content: '主人~该门店没有设置位置哦!',
          success: function (res) {
            if (res.confirm) {
              console.log('用户点击确定');
            } else if (res.cancel) {
              console.log('用户点击取消');
            }
          }
        });
        return;
      } else {
        wx.openLocation({
          latitude: latitude,
          longitude: longitude,
          scale: 12,
          name: name,
          address: address
        });
      }
    },
    gainUserLocation: function () {
      let that = this;
      wx.getLocation({
        type: 'gcj02',
        // 默认为 wgs84 返回 gps 坐标，gcj02 返回可用于 wx.openLocation 的坐标  
        success: function (res) {
          // success  
          console.log("===wx.getLocation===", res);
          var longitude = res.longitude;
          var latitude = res.latitude;
          that.needParam.longitude = longitude;
          that.needParam.latitude = latitude;
          that.setData({
            needParam: that.needParam
          });
        },
        fail: function (res) {
          // fail  
          console.log("===wx.getLocatiofailn===", res);
          wx.openSetting({
            success: function (res) {
              if (res.authSetting["scope.userLocation"] == true) {
                wx.showToast({
                  title: '授权成功',
                  icon: 'success',
                  duration: 1000
                }); //再次授权，调用wx.getLocation的API

                that.gainUserLocation();
              } else {
                wx.showToast({
                  title: '授权失败',
                  icon: 'none',
                  duration: 1000
                });
              }
            }
          });
        },
        complete: function () {
          // complete  
          console.log("===wx.getLocationcomplete===");
        }
      });
    },
    getUserLocation: function () {
      let that = this;
      wx.getSetting({
        success: res => {
          // res.authSetting['scope.userLocation'] == undefined    表示 初始化进入该页面
          // res.authSetting['scope.userLocation'] == false    表示 非初始化进入该页面,且未授权
          // res.authSetting['scope.userLocation'] == true    表示 地理位置授权
          if (res.authSetting['scope.userLocation'] != undefined && res.authSetting['scope.userLocation'] != true) {
            //未授权
            wx.showModal({
              title: '请求授权当前位置',
              content: '需要获取您的地理位置，请确认授权',
              success: function (res) {
                if (res.cancel) {
                  //取消授权
                  wx.showToast({
                    title: '拒绝授权',
                    icon: 'none',
                    duration: 1000
                  });
                } else if (res.confirm) {
                  //确定授权，通过wx.openSetting发起授权请求
                  wx.openSetting({
                    success: function (res) {
                      res.authSetting = {
                        "scope.userLocation": true
                      };
                    }
                  });
                }
              }
            });
          } else if (res.authSetting['scope.userLocation'] == undefined) {
            //用户首次进入页面,调用wx.getLocation的API
            console.log("用户首次进入页面", res);
            that.gainUserLocation();
          } else {
            console.log('授权成功'); //调用wx.getLocation的API

            that.gainUserLocation();
          }
        }
      });
    },
    tolinkUrl: function (e) {
      if (!getApp().globalData.loginUser) {
        wx.showModal({
          title: '提示',
          content: '主人~您还在登陆哦!稍等片刻',
          success: function (res) {
            if (res.confirm) {
              console.log('用户点击确定');
            } else if (res.cancel) {
              console.log('用户点击取消');
            }
          }
        });
        return;
      }

      let that = this;
      let linkUrl = e.currentTarget ? e.currentTarget.dataset.link : e;

      if (linkUrl.indexOf("nearby_stores.html") != -1) {
        console.log("选择门店");
        that.setData({
          reqStore: true
        });
      } else if (linkUrl.indexOf("location_servant_map.html") != -1) {
        console.log("选择服务人员");
        that.setData({
          reqServant: true
        });
      } else {
        that.setData({
          reqStore: false,
          reqServant: false
        });
      }

      getApp().globalData.linkEvent(linkUrl);
    },
    selectType: function (e) {
      console.log("====selectType====", e);
      let that = this;
      let type = e.currentTarget.dataset.type;

      if (that.allowMendianZiti == 3 && type == 0) {
        wx.showModal({
          title: '提示',
          content: '主人~您的订单不支持配送上门哦！',
          success: function (res) {
            if (res.confirm) {
              console.log('用户点击确定');
            } else if (res.cancel) {
              console.log('用户点击取消');
            }
          }
        });
        return;
      }

      that.setData({
        mendianZiti: type
      });
      that.getEditOrderDetail();
    },
    // 1提货人
    contactNameInput: function (e) {
      let that = this;
      console.log("提货人", e.detail.value);
      that.orderMessage.contactName = e.detail.value;
      that.setData({
        orderMessage: that.orderMessage
      });
    },
    // 1.提货人手机号
    contactTelnoInput: function (e) {
      let that = this;
      console.log("提货人手机号", e.detail.value);
      that.orderMessage.contactTelno = e.detail.value;
      that.setData({
        orderMessage: that.orderMessage
      });
    },
    check: function () {
      if (this.allowMendianZiti == "3") {
        this.setData({
          mendianZiti: 0
        });
      } else {
        this.setData({
          mendianZiti: 1
        });
      }

      console.log(this.mendianZiti);
      this.getEditOrderDetail();
    },
    uncheck: function () {
      console.log(this.allowMendianZiti);

      if (this.allowMendianZiti == "3") {
        this.setData({
          mendianZiti: 1
        });
      } else {
        this.setData({
          mendianZiti: 0
        });
      }

      console.log(this.mendianZiti);
      this.getEditOrderDetail();
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    loadMessage: function () {
      this.orderMessage.platformNo = getApp().globalData.setting.platformSetting.platformNo;
      this.orderMessage.userId = getApp().globalData.loginUser.id;
      this.orderMessage.orderNo = this.orderData.orderNo;

      if (this.orderData.orderJifen && this.orderData.orderJifen.tuijianDikou && this.jifenState) {
        this.orderMessage.jifenDikou = this.orderData.orderJifen.tuijianDikou;
      }

      this.orderMessage.gotCouponListId = this.gotCouponListId;
      this.orderMessage.addressId = this.orderData.addressId;
      this.orderMessage.contactName = this.orderData.contactName || "", this.orderMessage.contactTelno = this.orderData.contactTelno || "", console.log('----------------------------');
      console.log(this.orderMessage);
      console.log('----------------------------');
    },
    changOutAddr: function (addrEditParam) {
      getApp().globalData.addrEditParam = null;
      this.hasEditAddr = false;
      let orderData = this.orderData;
      orderData.buyerName = addrEditParam.contactName;
      orderData.buyerTelno = addrEditParam.telno;
      orderData.buyerProvince = addrEditParam.province;
      orderData.buyerCity = addrEditParam.city;
      orderData.buyerArea = addrEditParam.district;
      orderData.buyerAddress = addrEditParam.detail;
      this.orderMessage.addressId = addrEditParam.addressId;
      this.setData({
        orderData: orderData
      });
    },
    
    removeFile:function(event){
      let that=this;
      console.log('======event==',event);
      that.orderMessage.offPayedImage.splice(0,1)
    },
    addCommitImage: function (e) {
      console.log('===addCommitImage=',e)
      var that = this;
      let orderMessage=that.orderMessage;
      let count=1;
      if (orderMessage.offPayedImage.length==1){
        wx.showToast({
          title: "只能选一张",
          icon: 'none',
          duration: 2000
        })
        return
      }
      wx.chooseImage({
        count: 1, // 默认9
        sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
        success: function (res) {
          console.log("===chooseImage===",res)
          let tempFilePaths = res.tempFilePaths
          for (let i = 0; i < tempFilePaths.length;i++){
            that.uploadImage(tempFilePaths[i], tempFilePaths.length)
          }
        }
      })
    },
    uploadImage: function (tempFilePaths,count) {
      if (!getApp().globalData.loginUser) {
        getApp().globalData.echoErr('用户未登录')
        return
      }
      console.log("====count====",count)
      let that = this
      let param = {
        userId: getApp().globalData.loginUser.id
      }
      var customIndex = getApp().globalData.AddClientUrl("/file_uploading.html", param, 'POST')
      wx.uploadFile({
        url: customIndex.url, //接口地址
        filePath: tempFilePaths,
        name: 'file',
        formData: customIndex.params,
        header: {'content-type': 'multipart/form-data'},
        success: function (res) {
          var data = res.data
          console.log("===success===",data)
          if (typeof (data) == 'string') {
            data = JSON.parse(data)
            console.log("====string====",data)
            if (data.errcode == 0) {
              that.orderMessage.offPayedImage.splice(0,1,data.relateObj.imageUrl)
            }
          } else if (typeof (data) == 'object') {
            console.log("===object====", data)
            if (data.errcode == 0) {
                that.orderMessage.offPayedImage.splice(0,1,data.relateObj.imageUrl)
            }
          }
          console.log('==upLoadImageList==',that.orderMessage)
        }, fail: function (e) {
          console.log(e)
          wx.showToast({
            title: '图片上传失败...',
            icon: 'none',
            duration: 2000,
          })
        }, complete: function (e) {
    
        }
      })
    },
    offPayedRemarkFun:function(e){
        console.log("===offPayedRemarkFun===",e);
        let that=this;
        let value=e.detail.value;
        this.$set(that.orderMessage,"offPayedRemark",value)
    },
    setData: function (obj) {
      let that = this;
      let keys = [];
      let val, data;
      Object.keys(obj).forEach(function (key) {
        keys = key.split('.');
        val = obj[key];
        data = that.$data;
        keys.forEach(function (key2, index) {
          if (index + 1 == keys.length) {
            that.$set(data, key2, val);
          } else {
            if (!data[key2]) {
              that.$set(data, key2, {});
            }
          }

          data = data[key2];
        });
      });
    }
  }
};
</script>
<style scoped>
@import "./index.css";
</style>